package com.geek.service.impl;

import com.geek.bean.PageData;
import com.geek.mapper.MarketIssueMapper;
import com.geek.model.MarketIssue;
import com.geek.model.MarketIssueExample;
import com.geek.model.MarketUser;
import com.geek.service.IssueService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IssueServiceImpl implements IssueService {
    @Autowired
    private MarketIssueMapper mapper;

    @Override
    public List<MarketIssue> list() {
        MarketIssueExample example = new MarketIssueExample();
        example.createCriteria().andDeletedEqualTo(false);
        return mapper.selectByExample(example);
    }

    @Override
    public PageData list(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        MarketIssueExample example = new MarketIssueExample();
        example.createCriteria()
                .andDeletedEqualTo(false);
        List<MarketIssue> issueList = mapper.selectByExample(example);
        PageData pageData = new PageData();
        pageData.setLimit(limit);
        pageData.setPage(page);
        pageData.setList(issueList);
        pageData.setTotal(issueList.size());
        pageData.setPages(issueList.size() / limit + issueList.size() % limit == 0 ? 0 : 1);
        return pageData;
    }
}
